import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-02-13
 * Time: 15:32
 */
public class MyQueue {
    /**
     * LeetCode 232  用栈实现队列
     */

    // 解题思路：
    /**
     * 运用两个栈来进行队列的push，peek，pop，empty操作
     */

    //入栈到第一个栈，出栈在第二个栈
    private Stack <Integer> s1;
    private Stack <Integer> s2;

    public MyQueue() {
        s1=new Stack<>();
        s2=new Stack<>();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        if(empty()){
            return -1;
        }
        if(s2.isEmpty()){
            while(!s1.isEmpty()){
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    public int peek() {
        if(empty()){
            return -1;
        }
        if(s2.isEmpty()){
            while(!s1.isEmpty()){
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    public boolean empty() {
        return s1.isEmpty()&&s2.isEmpty();
    }
}
